<?php
/**
 * 管理员后台控制器
 * 
 * @version $Id: Term.php 645 2013-01-23 03:49:03Z linsir123 $
 */
class controllerTerm extends AdminController 
{
	/**
	 * @var 模型
	 */
	public $mTerms;
	
	/**
	 * 构造函数
	 */
	public function __construct()
	{
		$this->mTerms = MA::terms();
	}
	
	/**
	 * 首页
	 */
	public function actionIndex()
	{
		if (Request::isPost()) {
			set_time_limit(0);
			
			///
			$this->_echo("----------------------------------[保存]----------------------------------");
			$list = App::O('list', 'class');
			foreach ($list as $tmp) {
				$this->_save($tmp['title']);
				foreach ($tmp['sub'] as $v) 
					$this->_save($v[1]);
			}
			
			$list = App::O('zhe', 'class');
			foreach ($list as $title => $tmp) {
				$this->_save($title);
				foreach ($tmp as $v) 
					$this->_save($v[0]);
			}
			
			$list = App::O('classZhe', 'home');
			foreach ($list as $tmp) {
				foreach ($tmp['list'] as $v) 
					$this->_save($v);
			}
			
			$this->_save("女装");
			
		} else {
			View::display('term/index');
			View::assignSet(array(
				'title' => '关键字',
			));
		}
	}
	
	
	/// 以下为私有方法 ///
	
	
	/**
	 * 保存
	 */
	private function _save($term)
	{
		$id = $this->mTerms->save($term);
		///
		$this->_echo($id ." || ". $term);
	}
	
	/**
	 * 输出
	 */
	private function _echo($message)
	{
		echo '<script type="text/javascript">parent.displayResult("', $message, '");</script><br />';
		
		///
		ob_flush();
		flush();
	}
}
